/**
 * Created by 55456 on 2016/4/8.
 */
var BaseController = require("./BaseController");
var util = require("util");
var cache = require("../instances/cache");

var RegisterController = function RegisterController(attr){
    BaseController.apply(this,arguments);
};

util.inherits(RegisterController,BaseController);

RegisterController.prototype.register = function (ctx,db,user){
    //this.CheckAttr(arguments[0]);
    var createObj = user;
    var User = arguments[1];
    return User
        .create(createObj)
        .then(function (result) {
            //todo:define the unique str in the documentation
            var str = result.mobile + Math.random().toString(10).substring(2,8);
            var token = RegisterController.prototype.md5(str.toString());
            return {token: result.token,LoginToken:token,userID:result.id};
        });
};

var Register = new RegisterController("public");
module.exports = Register;
